package com.hook3.pianke.activity;

import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hook3.pianke.R;
import com.hook3.pianke.activity.infoLine.WebInfo;
import com.hook3.pianke.domain.TalkInfo;
import com.hook3.pianke.domain.TopicInfoDetail;

import org.xutils.common.Callback;
import org.xutils.x;

/**
 * Created by HOME on 2015/12/10.
 */
public class InfoActivity {
    private TextView talk_info_from_tx;
    private LinearLayout talk_info_more_group_v;
    private TextView talk_info_title_tx;
    private RelativeLayout talk_info_user_view;
    private com.hook3.pianke.view.CircleImageView talk_info_head_img;
    private TextView talk_info_user_name_tx;
    private ImageView talk_info_master_img;
    private TextView talk_info_time_tx;
    private LinearLayout talk_info_song_view;
    private TextView talk_info_song_name_tx;
    private TextView talk_info_song_singer_tx;
    private ImageView talk_info_cover_img;
    private ImageView talk_info_play_img;
    private ProgressBar talk_info_song_progress_bar;
    private TextView talk_info_song_time_tx;
    private Activity activity;
    private Toolbar toolbar;  //标题
    private FrameLayout frameLayout;//实现View;
    private View rootView;
    private TopicInfoDetail infoDetail;

    private TalkInfo postsinfo;
    private FrameLayout web_info;


    public InfoActivity(Activity activity, Toolbar toolbar, FrameLayout frameLayout, TopicInfoDetail infoDetail) {
        this.activity = activity;
        this.toolbar = toolbar;
        this.frameLayout = frameLayout;
        this.infoDetail = infoDetail;
        init();
    }

    private void init() {
        rootView = View.inflate(activity, R.layout.activity_info, null);
        talk_info_from_tx = (TextView) rootView.findViewById(R.id.talk_info_from_tx);
        talk_info_more_group_v = (LinearLayout) rootView.findViewById(R.id.talk_info_more_group_v);
        talk_info_title_tx = (TextView) rootView.findViewById(R.id.talk_info_title_tx);
        talk_info_user_view = (RelativeLayout) rootView.findViewById(R.id.talk_info_user_view);
        talk_info_head_img = (com.hook3.pianke.view.CircleImageView) rootView.findViewById(R.id.talk_info_head_img);
        talk_info_user_name_tx = (TextView) rootView.findViewById(R.id.talk_info_user_name_tx);
        talk_info_master_img = (ImageView) rootView.findViewById(R.id.talk_info_master_img);
        talk_info_time_tx = (TextView) rootView.findViewById(R.id.talk_info_time_tx);
        talk_info_song_view = (LinearLayout) rootView.findViewById(R.id.talk_info_song_view);
        talk_info_song_name_tx = (TextView) rootView.findViewById(R.id.talk_info_song_name_tx);
        talk_info_song_singer_tx = (TextView) rootView.findViewById(R.id.talk_info_song_singer_tx);
        talk_info_cover_img = (ImageView) rootView.findViewById(R.id.talk_info_cover_img);
        talk_info_play_img = (ImageView) rootView.findViewById(R.id.talk_info_play_img);
        talk_info_song_progress_bar = (ProgressBar) rootView.findViewById(R.id.talk_info_song_progress_bar);
        talk_info_song_time_tx = (TextView) rootView.findViewById(R.id.talk_info_song_time_tx);
        web_info = (FrameLayout) rootView.findViewById(R.id.web_info);
        talk_info_more_group_v.setVisibility(View.GONE); //我是商品详情页面所以我要去掉小组
        initData();
    }

    /**
     * 设置数据
     */
    private void initData() {
        postsinfo = infoDetail.getPostsinfo();
        talk_info_from_tx.setText("form:" + postsinfo.getGroupInfo().getTitle());  //标签
        talk_info_title_tx.setText(postsinfo.getTitle());//标题
        talk_info_user_name_tx.setText(postsinfo.getUserinfo().getUname());//名字
        ImageView imageView = new ImageView(activity);
        x.image().bind(imageView, postsinfo.getUserinfo().getIcon(), new MyCommonCallback());//头像
        talk_info_time_tx.setText(postsinfo.getAddtime_f());  //时间
        talk_info_user_view.setVisibility(View.VISIBLE);
        talk_info_user_name_tx.setVisibility(View.VISIBLE);
        talk_info_song_singer_tx.setVisibility(View.VISIBLE);
        frameLayout.addView(rootView);
        new WebInfo(activity, rootView, infoDetail,web_info);
    }


    class MyCommonCallback implements Callback.CommonCallback<Drawable> {
        @Override
        public void onSuccess(Drawable result) {
            talk_info_head_img.setImageDrawable(result);
        }

        @Override
        public void onError(Throwable ex, boolean isOnCallback) {

        }

        @Override
        public void onCancelled(CancelledException cex) {

        }

        @Override
        public void onFinished() {

        }
    }
}
